﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SudokuGame
{
    public partial class FrmNumber : Form
    {
        public FrmNumber()
        {
            InitializeComponent();
            SetStyle(
               ControlStyles.ResizeRedraw
               | ControlStyles.DoubleBuffer
               | ControlStyles.UserPaint
               | ControlStyles.AllPaintingInWmPaint
               | ControlStyles.SupportsTransparentBackColor,
               true
               );
            foreach (Control item in this.Controls)
            {
                item.Click += Item_Click;
            }
        }
        public Action<NumberArg> NumberCallback;
        public Point ClickPoint {  get; set; }
        public Point RowCell { get; set; }
        public Graphics Graphics { get; set; }
        private void Item_Click(object? sender, EventArgs e)
        {
            Button btn = sender as Button;
            NumberArg numberArg = new NumberArg();
            if (btn.Name == "btnClear")
            {
                numberArg.Type = NumberType.Clear;

            }
            else if (btn.Name == "btnClose")
            {
                numberArg.Type = NumberType.Close;
            }
            else
            {
                numberArg.Type = NumberType.Number;
                numberArg.Value = btn.Text;
            }
            numberArg.CllickPoint = ClickPoint;
            numberArg.RowCell = RowCell;
            numberArg.Graphics = Graphics;
            NumberCallback?.Invoke(numberArg);
            this.Close();
        }

        private void FrmNumber_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Dispose();
        }
    }
    public struct NumberArg
    {
        public NumberType Type { get; set; }
        public string Value { get; set; }
        public Point CllickPoint { get; set; }
        public Graphics Graphics { get; set; }
        public Point RowCell { get; set; }
    }
    public enum NumberType
    {
        Clear,
        Close,
        Number
    }
}
